import { BadGatewayException, Controller, Get, Query, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ModelType } from '@typegoose/typegoose/lib/types';
import { InjectModel } from 'nestjs-typegoose';
import { LunboModel } from 'src/mongodb/models/lunboModel/lunboModel';


@Controller('index')
export class BannerController {
    constructor(@InjectModel(LunboModel) private lunbo: ModelType<LunboModel>) { }


    @Get('getAdv')
    async getAdv() {
        try {
            const userlist = await this.lunbo.find()
            let lb = []
            let sy = []
            let xx = []
            if (userlist.length > 0) {
                userlist.forEach(element => {
                    if (element.type == '轮播广告') {
                        lb.push(element)
                    }
                    if (element.type == '首页广告') {
                        sy.push(element)
                    }
                    if (element.type == '消息广告') {
                        xx.push(element)
                    }
                });
            }
            return { data: { lb, sy, xx }, code: 200 }
        } catch (error) {
            throw new BadGatewayException(error)
        }
    }
}
